﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MazeRaider
{
    class Launcher
    {
        public static void Main()
        {
            MazeRaider mazeRaider = new MazeRaider();

            bool success = mazeRaider.ConnectToController();
            if (!success)
            {
                Console.WriteLine("Launch controller first");
                Console.ReadKey();
                Environment.Exit(0);
            }

            mazeRaider.RequestRobots();
            mazeRaider.SelectAlgorithm(AlgorithmEnum.DFS_ALGORITHM);

            while (true)
            {
                Console.WriteLine("\"Q\" to quit or other to (re)start");
                if ('Q'.Equals(char.ToUpperInvariant(Console.ReadKey().KeyChar)))
                {
                    break;
                }

                mazeRaider.Start();

                Console.WriteLine("Press any key to stop.");
                Console.ReadKey();
                mazeRaider.Stop();

                Console.WriteLine("Wait for agents to finish and then press any key to reset.");
                Console.ReadKey();
                mazeRaider.Reset();
            }

            mazeRaider.ReleaseRobots();
            mazeRaider.DisconnectFromController();
        }
    }
}
